<?php

namespace App\Admin;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
    protected $table = 'role';
    public $timestamps = false;
    // protected $fillable = ['age'];//可以被批量赋值的属性 
    // protected $guarded = ['id','price'];//不能被批量赋值的属性

    public function manager()
    {
        return $this->hasMany('App\Admin\Manager');
    }

     //将分派的权限进行处理
    public function assignAuth($data)
    {
    	//处理数据
        //获取auth_ids字段的值
        if (isset($data['auth_id'])) {
            $post['auth_ids'] = implode(',', $data['auth_id']);//1,2,3,4  数组变字符串
        } else {
            $post['auth_ids'] = '';
        }
        $post['role_name'] = $data['role_name'];
        $post['remark'] = $data['remark'];
    	//修改数据    update 返回受影响的行数
        return $this->where('id', $data['id'])->update($post);
    }

         //插入角色
    public function insertRole($data)
    {
             //处理数据
             //获取auth_ids字段的值
        if (isset($data['auth_id'])) {
            $post['auth_ids'] = implode(',', $data['auth_id']);//1,2,3,4  数组变字符串
        } else {
            $post['auth_ids'] = '';
        }
        $post['role_name'] = $data['role_name'];
        $post['remark'] = $data['remark'];
             //插入数据    insert 返回true 或 false
        return $this->insert($post);
    }
}
